package com.daocao.hua.view;

import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import com.daocao.hua.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2016/3/16 0016.
 */
public class PayMoneyDialog extends android.app.Dialog {


    @BindView(R.id.img_zhifubao)
    BottomIconText imgZhifubao;
    @BindView(R.id.img_weixin)
    BottomIconText imgWeixin;
    @BindView(R.id.img_yinlian)
    BottomIconText imgYinlian;
    @BindView(R.id.view_zhifubao)
    View viewZhifubao;

    public String ZHIFUBAO="ZHIFUBAO";
    public String WEIXIN="WEIXIN";
    public String YINLIAN="YINLIAN";
    public PayMoneyDialog(Context context) {
        super(context, R.style.mydialog);
        init();
    }

    public PayMoneyDialog(Context context, int themeResId) {
        super(context, themeResId);
    }

    public PayMoneyDialog setOnSelect(OnSureListener listener) {
        selectListener = listener;
        return this;
    }

    @OnClick({R.id.img_zhifubao, R.id.img_weixin, R.id.img_yinlian})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.img_zhifubao:
                if (selectListener != null)
                    selectListener.onSure(ZHIFUBAO);
                break;
            case R.id.img_weixin:
                if (selectListener != null)
                    selectListener.onSure(WEIXIN);
                break;
            case R.id.img_yinlian:
                if (selectListener != null)
                    selectListener.onSure(YINLIAN);
                break;
//            case R.id.img_jingdong:
//                if (selectListener != null)
//                    selectListener.onSure("jingdong");
//                break;
        }
    }

    public void setSelectVisible(String visible) {
//        1支付宝 2微信 3银行卡
        if (visible.contains("1")) {
            imgZhifubao.setVisibility(View.VISIBLE);
        } else {
            imgZhifubao.setVisibility(View.INVISIBLE);
        }
        if (visible.contains("2")) {
            imgWeixin.setVisibility(View.VISIBLE);
        } else {
            imgWeixin.setVisibility(View.INVISIBLE);
            viewZhifubao.setVisibility(View.INVISIBLE);
        }
        if (visible.contains("5")) {
            imgYinlian.setVisibility(View.VISIBLE);
        } else {
            imgYinlian.setVisibility(View.INVISIBLE);
        }
    }

    public interface OnSureListener {
        void onSure(String text);
    }

    private OnSureListener selectListener;

    private void init() {
        Window window = this.getWindow();
        window.requestFeature(Window.FEATURE_NO_TITLE);
        window.getDecorView().setPadding(0, 0, 0, 0);
        window.setWindowAnimations(R.style.mydialog_animation);
        setContentView(R.layout.dialog_pay_money);
        ButterKnife.bind(this);

        WindowManager.LayoutParams lp = window.getAttributes();
        lp.width = WindowManager.LayoutParams.MATCH_PARENT;
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        lp.gravity = Gravity.BOTTOM;
        window.setAttributes(lp);
        window.addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
        this.setCanceledOnTouchOutside(true);
    }


}
